<template>
  <div class="wrapper">
    <div class="content">
      <!-- hot -->
      <div class="hot">
        <div class="hot-title">热门城市</div>
        <ul class="hot-list">
          <li class="hot-item" v-for="item in hotCities" :key="item"
          @click="changeCityName(item.name)">
            {{ item.name }}
          </li>
        </ul>
      </div>
      <!-- sort -->
      <div class="sort">
        <div class="sort-title">字母排序</div>
        <ul class="sort-list">
          <li
            class="sort-item"
            v-for="(val, key) in cities"
            :key="key"
            @click="changeSort(key)"
          >
            {{ key }}
          </li>
        </ul>
      </div>
      <!-- list -->
      <div class="list">
        <div v-for="(val, key) in cities" :key="key" :ref="key">
          <div class="list-title">{{ key }}</div>
          <ul class="list-msg">
            <li class="list-item" v-for="item in val" :key="item.id"
            @click="changeCityName(item.name)">
              {{ item.name }}
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import BScroll from 'better-scroll' 
import { mapMutations } from 'vuex'
export default {
  name: "hot",
  props: ["cities", "hotCities"],
  components: {
  },
  data() {
    return {
      scroll: "",
    };
  },
  mounted(){
      let wrapper = document.querySelector('.wrapper')
      this.scroll = new BScroll(wrapper)
  },
  methods:{
      changeSort(sortName){
          this.scroll.scrollToElement(this.$refs[sortName][0]);
      },
      changeCityName(changeName){
          this.changeCity(changeName)
          this.$router.push("/")
      },
      ...mapMutations(['changeCity'])
  }
};
</script>

<style scoped lang="stylus">
@import '~css/common.styl';
.wrapper{
    position:absolute;
    top:.88rem;
    left:0;
    bottom:0;
    right:0;
    background:#fff;
    overflow:hidden;
}
.content{
    height:20000px;
}
.hot-title {
  font-size: 0.26rem;
  color: #212121;
  padding: 0.2rem 0.3rem;
}

.hot-list {
  background: #fff;
  font-size: 0.28rem;
  position: relative;
  overflow: hidden;
  color: #212121;
}

.hot-list:before {
  content: ' ';
  position: absolute;
  height: 100%;
  width: 33.3333%;
  left: 33.3333%;
  border-left: 0.02rem solid #ddd;
  border-right: 0.02rem solid #ddd;
}

.hot-item {
  text-align: center;
  height: 0.9rem;
  line-height: 0.9rem;
  float: left;
  width: 33.333%;
  border-bottom: 0.02rem solid #ddd;
  position:relative;
}

.sort-title {
  font-size: 0.24rem;
  color: #212121;
  padding: 0.2rem 0.3rem;
}

.sort-list {
  background: #fff;
  font-size: 0.28rem;
  position: relative;
  overflow: hidden;
  color: #212121;
}

.sort-item {
  text-align: center;
  height: 0.9rem;
  line-height: 0.9rem;
  float: left;
  width: 16.6666%;
}

.list-title {
  font-size: 0.24rem;
  color: #212121;
  padding: 0.2rem 0.3rem;
}

.list-item {
  width: 25%;
  font-size: 0.28rem;
  line-height: 0.9rem;
  float: left;
  border-bottom: 0.02rem solid #ddd;
  text-align: center;
  textOverflow();
  position:relative;
}

.list-msg {
  position: relative;
  overflow: hidden;
}

.list-msg:before {
  content: ' ';
  position: absolute;
  left: 25%;
  width: 25%;
  height: 100%;
  border-left: 0.02rem solid #ddd;
  border-right: 0.02rem solid #ddd;
}

.list-msg:after {
  content: ' ';
  position: absolute;
  right: 0;
  width: 0;
  height: 100%;
  border-left: 0.02rem solid #ddd;
}

.list-msg {
  background: white;
}
</style>